#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/wait.h>
int main(int argc, char const *argv[])
{
    int sum=100;
    printf("hello world\n");
    pid_t pid=  fork();
    if(pid==0)
    {   
        sum=sum-80;
        sleep(5);
        printf("当前为子进程 pid=%d,当前进程pid:%d  ,父进程的pid:%d\n ",pid,getpid(),getppid());
        printf("子进程sum=%d\n",sum);
        return -1;
        
    }else{
        int over_status=0;
       // waitpid(pid,&over_status,0);//用于等待 ，并且获得子进程结束后的结束状态

       // 循环检查子进程当前状态
        while(1)
        {
            pid_t cur_pid= waitpid(pid,&over_status,WNOHANG);
            printf( "当前子进程cur_pid=%d,当前子进程结束状态 %d   \n ",cur_pid ,over_status);
            sleep(1);
        }


        printf("子进程已结束,结束状态:%d\n",over_status);
        sum=sum+50;
        printf("当前为父进程 pid=%d,当前进程pid:%d  ,父进程的pid:%d\n ",pid,getpid(),getppid());
        printf("父进程sum=%d\n",sum);
    }
    printf("hello world33333333333\n");
   

    return 0;
}
